package com.example.ffepeg.ffpeg;

import ws.schild.jave.*;

import java.io.File;

public class Mp3ToWavConverter {
    public static void main(String[] args) {
        // 输入的mp3文件路径
        String inputFilePath = "C:\\Users\\Administrator\\Desktop\\1beab8e850964.mp3";
        // 输出的wav文件路径
        String outputFilePath = "src/main/resources/file/output.wav";

        // 创建音频属性实例
        AudioAttributes audio = new AudioAttributes();
        audio.setCodec("pcm_s16le"); // 设置输出格式为WAV

        // 创建编码属性实例并设置音频属性
        EncodingAttributes attrs = new EncodingAttributes();
        attrs.setFormat("wav");
        attrs.setAudioAttributes(audio);

        // 创建多媒体对象
        MultimediaObject multimediaObject = new MultimediaObject(new File(inputFilePath));

        try {
            // 开始转换过程
            Encoder encoder = new Encoder();
            encoder.encode(multimediaObject, new File(outputFilePath), attrs);
            System.out.println("转换完成！");
        } catch (EncoderException e) {
            e.printStackTrace();
        }
    }
}
